package service

import (
	"app.com/common.v1/tool"
	rpcClient "app.com/rpc.v1/rpc"
	demo "app.com/rpc.v1/rpc/proto"
	"context"
	"github.com/gin-gonic/gin"
)

type DemoService struct {
	clientRpc *rpcClient.Client
}

func NewDemoService(rpcClient *rpcClient.Client) *DemoService {
	return &DemoService{
		clientRpc: rpcClient,
	}
}

func (s *DemoService) Test(ctx *gin.Context) {
	ctx.Set("uuid", "lllllllllllllllllllllllll")
	ctx.Header("uuid", "***********")

	//header := metadata.New(map[string]string{"authorization": "this is nick", "space": "", "org": "", "limit": "", "offset": ""})
	//c := metadata.NewOutgoingContext(context.Background(), header)

	md, _ := ctx.Get("metadata")
	testDemo, err := s.clientRpc.DemoClient.TestDemo(md.(context.Context), &demo.TestDemoReq{Name: "哈哈"})
	if err != nil {
		tool.Error("TestDemo 调用失败")
		return
	}
	tool.Info(testDemo.Aa)
	tool.Info("test running")
}
